var postId;
var editor;
var replyId;
var userId;
var xhr;
/**
* 页面跳转
* @param current 当前页
* @param move 翻页码的动作
* @return
*/
function pageJump(current, move){

	var count = document.getElementById("countPage").value;
	var endPage = document.getElementById("lastpage").value;

	if(move != 0){
		current = document.getElementById("currentPage").value;
	}

	var html = "forum-postlist.html?move="+move+"&page.currentPage="+current+"&page.countPage="
			+count+"&endPage="+endPage;
	location.href=html;
}

function deletePost(id){
	postId = id;
	$( "#dialog-confirm" ).dialog( "open" );
}

function flower(id){
	$( "#flower-confirm" ).dialog( "open" );
	userId = id;
}
function flowersure(){
	var url = "json/forum-addFlower.html?userId="+userId;
	xhr = null;
	xhr = connectXHR(url, addFlower);
}
function addFlower(){
	if(xhr == null)return;
	if(xhr.readyState == 4 && xhr.status == 200) {
		var data = eval('(' + xhr.responseText + ')');
		
		if(data == 1){
			var classname = ".f" + userId;
			var flowers = $(classname);
			for(var i = 0; i < flowers.length; i++){
				var flower = flowers[i].innerHTML;
				var num = parseInt(flower);
				num = num + 1;
				flowers[i].innerHTML = num;
			}
		}else{
			
		}
	}
}

function egg(Id){
	$( "#egg-confirm" ).dialog( "open" );
	userId = Id;
}
function eggsure(){
	var url = "json/forum-addEgg.html?userId="+ userId;
	xhr = null;
	xhr = connectXHR(url, addEgg);
}
function addEgg(){
	if(xhr == null)return;
	if(xhr.readyState == 4 && xhr.status == 200) {
		var data = eval('(' + xhr.responseText + ')');
		
		if(data == 1){
			var eggs = $(".e"+userId);
			for(var i = 0; i < eggs.length; i++){
				var egg = eggs[i].innerHTML;
				var num = parseInt(egg);
				num = num + 1;
				eggs[i].innerHTML = num;
			}
		}else{
			
		}
	}
}

function reply(replyToId){
	$( "#replytopost" ).dialog( "open" );
	replyId = replyToId;
}
/**
 * 回复帖子
 * @return
 */
function sureToReply(){
//	var contentt = document.getElementById("replycontent").value;
	var topicId = document.getElementById("topicId").value;
	var postId = document.getElementById("postId").value;
//	alert(contentt);
	editor.sync();
	document.getElementById("Rreplyto").value=replyId;
	document.getElementById("replyForm").submit();
	location.href = "forum-replyPost.html?userReply.content='" + contentt + "'&topicId=" + topicId + "&postId=" + postId + "&replyTo=" + replyId;
}

function deleteReply(rid){
	$( "#dialog-confirm" ).dialog( "open" );
	replyId = rid;
}
function deletesure(){
	var topicId = document.getElementById("topicId").value;
	var postId = document.getElementById("postId").value;
	var current = document.getElementById("currentPage").value;
	location.href = "forum-deleteReply.html?topicId=" + topicId + "&postId=" + postId + "&replyId=" + replyId + "&page.currentPage="+current;
}